package com.tarena.lbs.message.web.controller;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.message.web.service.DynamicMsgFieldsService;
import com.tarena.lbs.pojo.message.dto.DynamicMsgFieldsDTO;
import com.tarena.lbs.pojo.message.param.DynamicMsgFieldsParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 动态字段管理控制器
 */
@RestController
@RequestMapping("/admin/message/dynamicMsgFields")
@Api(tags = "动态字段管理")
@CrossOrigin
public class DynamicMsgFieldsController {

    @Autowired
    DynamicMsgFieldsService dynamicMsgFieldsService;

    /**
     * 获取动态字段列表
     *
     * @return Result<List<DynamicMsgFieldsDTO>>对象
     */
    @GetMapping("/selectAll")
    public Result<List<DynamicMsgFieldsDTO>> selectAll() {
        List<DynamicMsgFieldsDTO> dtoList = dynamicMsgFieldsService.selectAll();
        return new Result<>(dtoList);
    }

    @ApiOperation("新增动态字段")
    @PostMapping("/insert")
    public Result<Void> insert(@RequestBody DynamicMsgFieldsParam param) {
        dynamicMsgFieldsService.insertDynamicMsgField(param);
        return Result.success();
    }
}
